-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow the GDT to be of any length #360
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me, only two minor things that need to be improved.
Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
pub struct GlobalDescriptorTable<const MAX: usize = 8> { | ||
table: [u64; MAX], | ||
next_free: usize, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit too late, but I just noticed that this design allows creating GDT's without any entries, but a GDT must always have at least a null entry, doesn't it?
The GDT can have a maxium length of 2^16 bytes, and must contain at least one null descriptor. As `MAX` counts the number of `u64` entries, we must have `0 < MAX <= 2^13`. Unfortunely, we cannot do this check with a `where` clause, as `feature(generic_const_expers)` is not yet stable. However, we can do this check with an `assert!` in `GlobalDescriptorTable::empty()`, which is a `const fn`. Pointed out by @Freax13 in #360 (comment) Signed-off-by: Joe Richey <joerichey@google.com>
This uses a const generic
MAX
parameter to specify the length. This is arguably a breaking change as it bumps the MSRV to 1.59 though its use of default const generics. It also can make some function call require additional type annotations:Fixes #333
Signed-off-by: Joe Richey joerichey@google.com